using System;
using System.Collections.Generic;
using System.IO;
using Common;

namespace SProject.Program
{
	[Serializable]
	public class MeltingSegment : BaseSegment
	{
		public static int SCAN_CONTINUE = 0;

		public static int SCAN_STEP = 1;

		public string Name { get; set; }

		public int ScanMode { get; set; }

		public double Rate { get; set; }

		public double Interval { get; set; }

		public int HoldTime { get; set; }

		public double StartTemp { get; set; }

		public double EndTemp { get; set; }

		public bool IsHRM { get; set; }

		public MeltingSegment()
		{
			ScanMode = SCAN_CONTINUE;
			Rate = 0.01;
			Interval = 1.0;
			HoldTime = 15;
			StartTemp = 45.0;
			EndTemp = 80.0;
			IsHRM = false;
		}

		public override void Copy(BaseSegment BaseSegment)
		{
			MeltingSegment meltingSegment = BaseSegment as MeltingSegment;
			if (meltingSegment != null)
			{
				Name = meltingSegment.Name;
				ScanMode = meltingSegment.ScanMode;
				Rate = meltingSegment.Rate;
				Interval = meltingSegment.Interval;
				HoldTime = meltingSegment.HoldTime;
				StartTemp = meltingSegment.StartTemp;
				EndTemp = meltingSegment.EndTemp;
				IsHRM = meltingSegment.IsHRM;
			}
		}

		public override BaseSegment Clone()
		{
			MeltingSegment meltingSegment = new MeltingSegment();
			meltingSegment.Copy(this);
			return meltingSegment;
		}

		public override int GetHashCode()
		{
			return base.GetHashCode();
		}

		public override bool Equals(object obj)
		{
			if (obj == null)
			{
				return false;
			}
			MeltingSegment meltingSegment = obj as MeltingSegment;
			if (meltingSegment == null)
			{
				return false;
			}
			if (base.Equals(meltingSegment))
			{
				return true;
			}
			if (ScanMode == meltingSegment.ScanMode && ((ScanMode == SCAN_CONTINUE && Rate == meltingSegment.Rate) || (ScanMode == SCAN_STEP && Interval == meltingSegment.Interval && HoldTime == meltingSegment.HoldTime)) && StartTemp == meltingSegment.StartTemp && EndTemp == meltingSegment.EndTemp)
			{
				return IsHRM == meltingSegment.IsHRM;
			}
			return false;
		}

		public override void SaveToStream(StreamEx stream)
		{
			stream.Write(PropertyKey.Key_MeltingSegment);
			List<PropertyKey> list = new List<PropertyKey>();
			List<byte[]> list2 = new List<byte[]>();
			if (!string.IsNullOrEmpty(Name))
			{
				list.Add(PropertyKey.Key_Name);
				list2.Add(BytesConverter.GetBytes(Name));
			}
			list.Add(PropertyKey.Key_ScanMode);
			list2.Add(BytesConverter.GetBytes(ScanMode));
			list.Add(PropertyKey.Key_Rate);
			list2.Add(BytesConverter.GetBytes(Rate));
			list.Add(PropertyKey.Key_Interval);
			list2.Add(BytesConverter.GetBytes(Interval));
			list.Add(PropertyKey.Key_HoldTime);
			list2.Add(BytesConverter.GetBytes(HoldTime));
			list.Add(PropertyKey.Key_StartTemp);
			list2.Add(BytesConverter.GetBytes(StartTemp));
			list.Add(PropertyKey.Key_EndTemp);
			list2.Add(BytesConverter.GetBytes(EndTemp));
			list.Add(PropertyKey.Key_IsHRM);
			list2.Add(BytesConverter.GetBytes(IsHRM));
			stream.Write(PropertyKey.Key_Index);
			stream.WriteIndex(list, list2);
			stream.Flush();
		}

		public override bool ReadFromStream(StreamEx stream)
		{
			PropertyKey propertyKey = stream.ReadKey();
			if (propertyKey == PropertyKey.Key_MeltingSegment)
			{
				propertyKey = stream.ReadKey();
				if (propertyKey == PropertyKey.Key_Index)
				{
					List<PropertyKey> keys;
					List<byte[]> dates;
					stream.ReadIndex(out keys, out dates);
					for (int i = 0; i < keys.Count; i++)
					{
						switch (keys[i])
						{
						case PropertyKey.Key_Name:
							Name = BytesConverter.BytesToString(dates[i]);
							break;
						case PropertyKey.Key_ScanMode:
							ScanMode = BytesConverter.BytesToInt(dates[i]);
							break;
						case PropertyKey.Key_Rate:
							Rate = BytesConverter.BytesToDouble(dates[i]);
							break;
						case PropertyKey.Key_Interval:
							Interval = BytesConverter.BytesToDouble(dates[i]);
							break;
						case PropertyKey.Key_HoldTime:
							HoldTime = BytesConverter.BytesToInt(dates[i]);
							break;
						case PropertyKey.Key_StartTemp:
							StartTemp = BytesConverter.BytesToDouble(dates[i]);
							break;
						case PropertyKey.Key_EndTemp:
							EndTemp = BytesConverter.BytesToDouble(dates[i]);
							break;
						case PropertyKey.Key_IsHRM:
							IsHRM = BytesConverter.BytesToBool(dates[i]);
							break;
						}
					}
					return true;
				}
				stream.Seek(-4L, SeekOrigin.Current);
				while (true)
				{
					switch (stream.ReadKey())
					{
					case PropertyKey.Key_Name:
						Name = stream.ReadString();
						break;
					case PropertyKey.Key_ScanMode:
						ScanMode = stream.ReadInt();
						break;
					case PropertyKey.Key_Rate:
						Rate = stream.ReadDouble();
						break;
					case PropertyKey.Key_Interval:
						Interval = stream.ReadDouble();
						break;
					case PropertyKey.Key_HoldTime:
						HoldTime = stream.ReadInt();
						break;
					case PropertyKey.Key_StartTemp:
						StartTemp = stream.ReadDouble();
						break;
					case PropertyKey.Key_EndTemp:
						EndTemp = stream.ReadDouble();
						break;
					case PropertyKey.Key_IsHRM:
						IsHRM = stream.ReadBool();
						break;
					default:
						stream.Seek(-4L, SeekOrigin.Current);
						return true;
					}
				}
			}
			stream.Seek(-4L, SeekOrigin.Current);
			return false;
		}
	}
}
